import http from '@/libs/http'

// 航班变更管理相关API
export default {
  // 航班航线变更
  getFlightRouteChangeList(params: any) {
    return http.get('/api/flightRouteChange/list', { params })
  },

  getFlightRouteChangeById(id: number) {
    return http.get(`/api/flightRouteChange/${id}`)
  },

  createFlightRouteChange(data: any) {
    return http.post('/api/flightRouteChange', data)
  },

  updateFlightRouteChange(data: any) {
    return http.put('/api/flightRouteChange', data)
  },

  deleteFlightRouteChange(id: number) {
    return http.delete(`/api/flightRouteChange/${id}`)
  },

  deleteBatchFlightRouteChange(ids: number[]) {
    return http.delete('/api/flightRouteChange/batch', { data: ids })
  },

  // 发起审批
  submitFlightRouteChange(id: number, data: any) {
    console.log(2332322323,id)
    return http.post(`/api/flightRouteChange/${id}/submit`, data)
  },

  // 审核
  auditFlightRouteChange(data: any) {
    // data: { id, approved, comments, approverId, approverName }
    const { id, approved, comments, approverId, approverName } = data
    const params = new URLSearchParams({
      approved: String(approved),
      approverId: String(approverId),
      approverName: approverName || ''
    })
    if (comments) params.append('comments', comments)
    return http.post(`/api/flightRouteChange/${id}/approve?${params.toString()}`)
  },

  // 航班航线变更历史
  getFlightRouteChangeHistoryList(params: any) {
    return http.get('/api/flightRouteChangeHistory/list', { params })
  }
}

// 航班航线变更具名导出
export const getFlightRouteChangePage = (params: any) => {
  return http.get('/api/flightRouteChange/list', { params })
}

export const getFlightRouteChangeById = (id: number) => {
  return http.get(`/api/flightRouteChange/${id}`)
}

export const addFlightRouteChange = (data: any) => {
  return http.post('/api/flightRouteChange', data)
}

export const updateFlightRouteChange = (data: any) => {
  return http.put('/api/flightRouteChange', data)
}

export const deleteFlightRouteChange = (id: number) => {
  return http.delete(`/api/flightRouteChange/${id}`)
}

export const deleteBatchFlightRouteChange = (ids: number[]) => {
  return http.delete('/api/flightRouteChange/batch', { data: ids })
}

export const submitFlightRouteChangeForApproval = (id: number) => {
  return http.post(`/api/flightRouteChange/submit-approval/${id}`)
}

export const auditFlightRouteChange = (data: any) => {
  return http.post('/api/flightRouteChange/audit', data)
}

// 航班航线变更历史具名导出
export const getFlightRouteChangeHistoryPage = (params: any) => {
  return http.get('/api/flightRouteChangeHistory/list', { params })
} 